package org.lgiavedoni.android.franq.core.httpserver;

import java.lang.reflect.Method;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.velocity.VelocityContext;
import org.lgiavedoni.android.franq.service.log.Logger;

public abstract class HttpPageController {

	public VelocityContext processRequest(VelocityContext context, Map<String, String> params) {
		if (params.containsKey("action")) {
			try {
				String methodName = "action" + StringUtils.capitalize(params.get("action"));
				Method m = this.getClass().getMethod(methodName, context.getClass(), params.getClass());
				return (VelocityContext) m.invoke(this, context, params);
			} catch (Exception e) {
				Logger.inst.error(e);
				return context;
			}

		} else {
			return actionDefault(context);
		}

	}

	public abstract VelocityContext actionDefault(VelocityContext context);

	public abstract String getTemplateName(Map<String, String> params);

	public abstract String getPath();

}
